home *** CD-ROM | disk | FTP | other *** search
/ Nothing but Tetris / Nothing but Tetris.iso / amiga / workbench_tris / txttobin.c < prev   
C/C++ Source or Header  |  1992-11-19  |  2KB  |  82 lines

  1. /* 
  2. Copyright (c) 1992, Trevor Smigiel.  All rights reserved.
  3.  
  4. (I hope Commodore doesn't mind that I borrowed their copyright notice.)
  5.  
  6. The source and executable code of this program may only be distributed in free
  7. electronic form, via bulletin board or as part of a fully non-commercial and
  8. freely redistributable diskette.  Both the source and executable code (including
  9. comments) must be included, without modification, in any copy.  This example may
  10. not be published in printed form or distributed with any commercial product.
  11.  
  12. This program is provided "as-is" and is subject to change; no warranties are
  13. made.  All use is at your own risk.  No liability or responsibility is assumed.
  14.  
  15. */
  16.  
  17. #include <exec/types.h>
  18. #include <intuition/intuition.h>
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include "Tetris.h"
  22.  
  23. #include <proto/exec.h>
  24. #include <proto/dos.h>
  25. #include <proto/graphics.h>
  26. #include <proto/intuition.h>
  27.  
  28. int
  29. main(int argc, char *argv[])
  30. {
  31.     BPTR infile, outfile;
  32.     char buf[32];
  33.     struct TLevel level;
  34.     int i, j;
  35.  
  36.     infile  = Input();
  37.     Flush(infile);
  38.     outfile = Output();
  39.     Flush(outfile);
  40.  
  41.     switch (argc) {
  42.     case 3:
  43.         outfile = Open(argv[2], MODE_NEWFILE);
  44.     case 2:
  45.         infile  = Open(argv[1], MODE_OLDFILE);
  46.         break;
  47.     }
  48.  
  49.         FGets(infile, buf, 31);
  50.         stcd_i(buf, &j);
  51.         level.goal = j;
  52.  
  53.         FGets(infile, buf, 31);
  54.         stcd_i(buf, &j);
  55.         level.lines = j;
  56.  
  57.         FGets(infile, buf, 31);
  58.         stcd_i(buf, &j);
  59.         level.time = j;
  60.  
  61.         FGets(infile, buf, 31);
  62.         stcd_i(buf, &j);
  63.         level.line_up = j;
  64.         for (i = 0; i < PFHEIGHT; i++) {
  65.             FGets(infile, buf, 31);
  66.             stch_i(buf, &j);
  67.             level.board[i] = (j << 5) | 0x801f;
  68.         }
  69.         level.board[PFHEIGHT] = 0xffff;
  70.  
  71.         Write(outfile, &level, sizeof(struct TLevel));
  72.  
  73.     switch (argc) {
  74.     case 3:
  75.         Close(outfile);
  76.     case 2:
  77.         Close(infile);
  78.         break;
  79.     }
  80.     return 0;
  81. }
  82.